from tkinter import *
class WidgetDemo:
    def __init__(self):
        window = Tk()
        window.title("测试")
        frame1 = Frame(window)
        frame1.pack()

        self.v1 = IntVar()
        cbtBold = Checkbutton(frame1,text='粗体',variable=self.v1,command=self.processCheckbutton)

        self.v2 = IntVar()
        rbRed = Radiobutton(frame1,text='红色',bg='red',variable=self.v2,value=1,command=self.processRadiobutton)
        rbYellow = Radiobutton(frame1,text='黄色',bg='yellow',variable=self.v2,value=2,command=self.processRadiobutton)
        cbtBold.grid(row=1,column = 1)
        rbRed.grid(row=1,column = 2)
        rbYellow.grid(row=1,column=3)

        frame2 = Frame(window)
        frame2.pack()

        label = Label(frame2,text='请输入你的名字：')
        self.name = StringVar()
        entryName = Entry(frame2,textvariable=self.name)
        btGetName = Button(frame2,text='获取名字',command=self.processButton)
        message = Message(frame2,text='it is a widgets demo')

        label.grid(row=1,column = 1)
        entryName.grid(row=1,column = 1)
        btGetName.grid(row = 1,column = 3)
        message.grid(row = 1,column = 4)

        text = Text(window)

        text.pack()
        text.insert(END,'tip\n the best way to learn tkinter is to read')
        text.insert(END,'these carefully designed examples and use them ')
        text.insert(END,'to create your application.')

        window.mainloop()

    def processCheckbutton(self):
        print("check button is "+ ("check" if self.v1.get() == 1 else "unchecked"))

    def processRadiobutton(self):
        print( ("red" if self.v2.get() == 1 else "yellow") + "is selected")

    def processButton(self):
         print("you name is "+self.name.get())

WidgetDemo()